﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<style type="text/css">
    .ui-jqgrid .ui-jqgrid-pager .ui-pager-table,
    .ui-jqgrid .ui-jqgrid-toppager .ui-pager-table {
        width: 95%;
    }
</style>
<script type="text/javascript">
    var numberArray = [];
    $(function () {
        initControl();
        gridList();
        if ($('#txt_result').val().length > 0) {
            numberArray = $('#txt_result').val().split(',');
        }
    });
    function initControl() {
        //$('select').bindSelect();
    }
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/BOM/Manufacture/GetCarModelJson",
            height: 170,
            colModel: [
                {
                    label: '选择', name: 'VEHICLENUMBER', width: 40, align: 'center', sortable: false, frozen: true, formatter: function (cellvalue, options, rowObject) {
                        var currentList = $('#txt_result').val().split(',');
                        var index = findElement(currentList, cellvalue);
                        //alert(currentList + ': ' + cellvalue + ': ' + index);
                        var chb_status = '';
                        if (index >= 0) {
                            chb_status = 'checked="checked"';
                        }
                        return '<input class="grid_chb_select" value="' + cellvalue + '" name="checkbox" ' + chb_status + ' type="checkbox" onclick="item_selected(this);" style="vertical-align:middle">';
                    }
                },
                { label: '整车编号', name: 'VEHICLENUMBER', width: 130, align: 'left', frozen: true, sortable: false },
                { label: '车型代号', name: 'VETYPENUMBER', width: 80, align: 'left', frozen: true, sortable: false },
                { label: '产品信函编号', name: 'HT031', width: 90, align: 'center', sortable: false },
                { label: '产品型号', name: 'PRODUCTNUMBER01', width: 150, align: 'left', sortable: false },
            ],
            pager: "#gridPager",
            sortname: 'VEHICLENUMBER ASC',
            viewrecords: true,
            rownumWidth: 40,
            ondblClickRow: function (rowid) {
                //var rowData = $gridList.jqGrid('getRowData', rowid);
                //do_choose_makeline(rowData.MakeLineNO);
            }
        });
        $gridList.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: { keyword: $("#txt_keyword").val() },
            }).trigger('reloadGrid');
        });
    }
    function item_selected(obj) {
        var val = $(obj).val();
        var index = findElement(numberArray, val);
        if ($(obj).prop("checked")) {
            if (index < 0) {
                numberArray.push(val);
            }
        } else {
            if (index >= 0) {
                numberArray.splice(index, 1)
            }
        }
        //alert(numberArray.length);
        $("#txt_result").val(numberArray.join(','));
    }
    function findElement(arrayToSearch, val) {
        for (var i = 0; i < arrayToSearch.length; i++) {
            if (arrayToSearch[i] == val) {
                return i;
            }
        }
        return -1;
    }
    function btn_ok() {
        var father = $.currentSubSubWindow().frames["Detail"];
        father.do_set_carmodel($('#txt_result').val());
    }
</script>
<div id="layout" style="height: 100%; width: 100%; ">
    <div style="padding: 12px 0 2px 0; padding-left: 15px; border-bottom: 1px solid #ccc; " class="line-table input-width-360">
        <label class="prefix">已选车型</label> <input id="txt_result" name="txt_result" type="text" class="form-control" value="@ViewBag.numbers" /> 
        <div class="btn-group" style="">
            <a id="btn_ok" class="btn btn-primary center-block btn-1" onclick="btn_ok()"><span class="glyphicon glyphicon-ok"></span> 确定</a>
        </div>
    </div>
    <div style="padding: 2px 0 5px 0; padding-left: 15px; border-bottom: 1px solid #ccc; " class="line-table input-width-185">
        <label class="prefix">整车编号</label> <input id="txt_keyword" type="text" class="form-control" />
        <div class="btn-group" style="">
            <a id="btn_search" class="btn btn-primary center-block btn-1" onclick=""><span class="glyphicon glyphicon-search"></span> 检索</a>
        </div>
    </div>
    <div>
        <table id="gridList"></table>
        <div id="gridPager"></div>
    </div>
</div>

